#include <project.h>
#include <aclconio.h>
#include <stdio.h>
#include <stdlib.h>
#include <acldev.h>
#include <aclstr.h>
#include <aclutil.h>
#include <prot8583.h>
#include <define.h>
#include <transact.h>
#include <dbmgr.h>
#include <protocol.h>
#include <packet.h>
#include <tran.h>
#include <comm.h>
#include <modem.h>
#include <ppt.h>
#include <piputl.h>
#include <pipmsg.h>
#include <isoutl.h>
#include <isoload.h>
#include <ifldtbl.h>
#include <msg.h>
#include <msgfuncs.h>
#include <bdt.h>
#include <hdt.h>
#include <trt.h>
#include <mht.h>
#include <iit.h>
#include <accum.h>
#include <form.h>
#include <date.h>
#include <mem.h>
#include <spdebug.h>
#include <funcids.h>
#include <pbatch.h>
#include <errno.h>
#include <ascii.h>
#include <amexhost.h>
#include <pct.h>
#include <formater.h>
#include <table.h>
#include <string.h>
#include <confio.h>
#include <aclfile.h>
#include <format.h>
#include <spamsg.h>
#include <oper.h>
#include <batmsg.h>
#include <ui.h>
#include <tct.h>
#include <multilng.h>
#include <logo.h>
#include <settlbat.h>
#include <msgclrk.h>
#include <msgshf.h>
#include <menufunc.h>
#include <mit.h>
#include <applidl.h>
#include <tblutil.h>
#include <menus.h>
#include <Validt.h>
#include <stats.h>
#include <cardmsg.h>
#include <card.h>
#include <msg.h>
#include <define.h>
#include <entry.h>
#include <pinpad.h>
#include <ctype.h>
#include <cdt.h>
#include <funcs.h>

#include "..\..\hostsrc\cpacsrc\cpacmsg.h"
#include "..\..\hostsrc\cpacsrc\cpacsize.h"
#include "..\..\hostsrc\cpacsrc\cpac.h"
#include "..\..\hostsrc\cpacsrc\sqautils.h"
#include "..\..\hostsrc\cpacsrc\cpacids.h"

#include "..\..\hostsrc\ICICsrc\ICICids.h"
#include "..\..\hostsrc\ICICsrc\ICICmsg.h"
#include "..\..\hostsrc\ICICsrc\ICICsrc.h"
#include "..\..\hostsrc\ICICsrc\ICICSize.h"


#include "BASEids.h"
#include "BASEmsg.h"
#include "BASE24.h"
#include "BASEsize.h"

#define FNAME_SIZE   10
#define BASE24_INIT_FILE            "INIT.DAT"
#define BASE24_SEND_SIZE                512

field_struct srFieldBASE24ISOFDT;
char szField60Length[10 + 1];
char szAXAPAuthCode[AUTH_CODE_SIZE + 1];
unsigned char szBASE24Field60[BASE24_FIELD60_SIZE + 1];
char szAmexTermId[8+1];/*cpacsrc.c in softpay*/
char szAmexMerchId[15+1];/*cpacsrc in softpay*/
char szAmexHdr1[40+1], szAmexHdr2[40+1];
char szICICITermId[8+1];
char szICICIMerchId[15+1];
//Added by Renu
char szICICNII[NII_SIZE+1];
char szAMEXNII[NII_SIZE+1];
int checkICICITIDFlag=0;
int checkICICIMIDFlag =0;
long inICICIBatchNum=0;

int intableIds[] = {
    1,
    2,
    3,
    4,
    5
};

extern ISOLOAD srCITILoadDataFuncs[];
extern char szCITIField62[CITI_FIELD62_SIZE + 1];
extern field_struct srFieldCITIISOFDT;
extern int hClock;

/* Fix for Bug No 4 in Predator ICIC List  */
extern unsigned short uinCurrentState;
/* Fix for Bug No 4 in Predator ICIC List  */

short inGTransactionType = 0;

int inGetField60Length(void);
VS_BOOL fProcLastDigit = VS_FALSE;
extern void vdAddBase24Functions(void);
extern int inReconcileCPAC(TRANSACTION_OBJECT* pobTran);
extern int inBASE24Init(TRANSACTION_OBJECT* pobTran);
extern int inCPACPIPAnalyse(PACKET_OBJECT* pobPacket);
extern int inCPACPIPDeinitialize(PACKET_OBJECT* pobPacket);
extern void vdInitializeBASE24(PACKET_OBJECT* pobPacket);
extern int inInitializeCPACValidationStruct(TRANSACTION_OBJECT* pobTran,VALIDATION_STRUCT* psrValidationParameters);
extern int inUpdateCPACReversal(COMM_8583_DATA* srCommStruct);
extern int inModifyCPACBatchRec(TRANSACTION_OBJECT* pobTran);
extern int inCPACBaseRespValidation(VALIDATION_STRUCT* psrRespValStruct,int  inInternalVal);
int inBASE24InitializeTran(TRANSACTION_OBJECT* pobTran);
int inBase24CheckTranAllowed(TRANSACTION_OBJECT* pobTran);
int inBase24PreauthAllowed(TRANSACTION_OBJECT* pobTran);
int inBase24InitAllowed(TRANSACTION_OBJECT* pobTran);
extern void vdLoadCPACParams(CPAC_REC* psrCPAC);
extern int inGetBatchRecCnt(DB_FILE* psrDBF);
extern int inGetBatchRec(TRANSACTION_OBJECT* pobTran,int inRecNum);
extern int inRunFunction(TRANSACTION_OBJECT* pobTran,int inFieldID);
extern int inWriteBatchData(DB_FILE* psrDBF,BATCH_KEY* psrBKey,BATCH_REC* psrBRec,long lnRecNum);
int inBaseAddBatchRec(TRANSACTION_OBJECT* pobTran,BATCH_KEY* psrBKey,BATCH_REC* psrBRec,long lnRecNum);






void vdAddBase24Functions(void) {
    inAddFunctionPointer(BASE24_INIT_PACKET, (PFI) vdInitializeBASE24);
    inAddMessageFileName(BASE24_NAME_ID, "bmsg");
    inAddFunctionPointer(BASE24_INIT_INITIALIZE, inBASE24InitializeTran);
    inAddFunctionPointer(BASE24_TRANS_VERIFICATION, inBase24CheckTranAllowed); /*venu_added*/
    inAddFunctionPointer(BASE24_PREAUTH_VERIFICATION, inBase24PreauthAllowed);
    inAddFunctionPointer(BASE24_INIT_ALLOWED, inBase24InitAllowed);
    inAddFunctionPointer(BASE24_UPDATE_TABLES, inBase24UpdateHdfcTables);
    inAddFunctionPointer(EDIT_BASE24_INI, inEditBase24INIOperation);
    inAddFunctionPointer(BASE24_RESET_INIT_FLAG, inBase24ResetInitFlag);
    inAddFunctionPointer(BASE24_CHKALL_MER_BAT_MT, inChkAllMerchBatchEmpty);
    inAddFunctionPointer(BASE24_DISP_MESSAGE, inBase24DisplayMessage);
    inAddFunctionPointer(HDFC_INIT_FUNCTION, inFixBASE24Initialize);
    inAddFunctionPointer(AXAP_GET_AUTH_CODE1, inAXAPGetAuthCode1);
    inAddFunctionPointer(AXAP_SET_AUTH_CODE1, inAXAPSetAuthCode1);
    inAddFunctionPointer(UPDATE_MULTIMERCHANT, (PFI_TO) inUpdateMIDMultimerchant);
    inAddFunctionPointer(ICICI_INIT_RESTART, inICICIRestartAfterInit);
     inAddFunctionPointer(ICICI_AMEX_SET_TRACK, inICICISetTrack);
    inOverloadFieldID(SET_MODEM_OBJECT, (PFI_TO) inBase24DefaultSetModemObjectFunctions);
}

void vdInitializeBASE24(PACKET_OBJECT* pobPacket) {
    pobPacket->inInitialize = (PFI_VD) inBASE24Init;
    pobPacket->inAnalyse = (PFI_VD) inCPACPIPAnalyse;
    pobPacket->inDeinitialize = (PFI_VD) inCPACPIPDeinitialize;
}

int inBASE24Init(TRANSACTION_OBJECT* pobTran) {
    /*srFieldCITIISOFDT.field_num = 62;
    srFieldCITIISOFDT.packet_sz = CITI_FIELD62_SIZE;
    srFieldCITIISOFDT.convert_idx = AV3_STR;
    srFieldCITIISOFDT.reference = szCITIField62;
    srFieldCITIISOFDT.var_sz = CITI_FIELD62_SIZE + 1;*/

#if 0
    if (inCPACCreateVariantStruct60() == VS_ERR)
    {
        vdFree((char *)psrVariant60);
        vdSGErrorMessage(NO_MEM_ERR_MSG);

        return(VS_ERR);
    }
#endif /* 0 */

    if (inCITICreateVariantStruct63() == VS_ERR) {
        vdFreeVariantTables();
        vdSGErrorMessage(NO_MEM_ERR_MSG);

        return(VS_ERR);
    }
    //  vdOverLoadISOFDT(FIELD62_POSITION, &srFieldCITIISOFDT );

    vdOverLoadLoadDataFuncs(srCITILoadDataFuncs);


    memset(srISO.pszField37, 0, sizeof(srISO.pszField37));  // CPAC_UNBKL added
    memset(srISO.pszField38, 0, sizeof(srISO.pszField38));  // CPAC_UNBKL added

    srFieldBASE24ISOFDT.field_num = 60;
    srFieldBASE24ISOFDT.packet_sz = BASE24_FIELD60_SIZE;
    srFieldBASE24ISOFDT.convert_idx = AV3_AV3;
    srFieldBASE24ISOFDT.reference = szBASE24Field60;
    srFieldBASE24ISOFDT.var_sz = BASE24_FIELD60_SIZE + 1;
    vdOverLoadISOFDT(FIELD60_POSITION, &srFieldBASE24ISOFDT);

    vdOverLoadLoadDataFuncs(srCITILoadDataFuncs);
    inOverloadFieldID(INIT_VALIDATION_STRUCT, (PFI_TO) inInitializeCPACValidationStruct);
    inOverloadFieldID(MODIFY_BATCH_REC, inModifyCPACBatchRec);
    //     inOverloadFieldID(SET_TRANS_FIELDS, inSetHDFCTransFields);
    inOverloadFieldID(SET_TRANS_FIELDS, (PFI_TO) inSetCITITransFields);

    inOverloadFieldID(UPDATE_REVERSAL, (PFI_TO) inUpdateCPACReversal);   // CPAC_UNBKL added

    /** /pdebug(("--inReconcileCPAC--"));*/

    return (VS_SUCCESS);
}



int inBASE24InitializeTran(TRANSACTION_OBJECT* pobTran) {
    int inRetVal;
    short inMyTranCode;
    short inPIPTransCode;
    char szFName[FNAME_SIZE + 1];
    PACKET_OBJECT obPacket;
    int inIndex = 0;

    inPFRStateStoreAll(BASE24_PFR_IDLE_STATE, pobTran, 1, 1);

    ACTIVITY_LOG("Initialization started");

    //    char szInitTID[CPAC_TERM_ID_SIZE+1];
    //     char szInitPhoneNum[PHONE_NUM_SIZE+1];
    //     char szInitNII[CPAC_NII_SIZE + 1];
    //     char szInitTPDU[CPAC_TPDU_SIZE + 1];
    //     char szInitPABXCode[PABX_CODE_SIZE + 1];
    //     int inVFHostIndex = 0;
    //   CPT_REC  srLocalCPTRec;
    //   HDT_REC  srLocalHDTRec;


    //       memset(szInitNII, '\0', sizeof(szInitNII));
    //       memset(szInitTID, '\0', sizeof(szInitTID));
    //       memset(szInitTPDU, '\0', sizeof(szInitTPDU));
    //       memset(szInitPhoneNum, '\0', sizeof(szInitPhoneNum));
    //       memset(szInitPABXCode, '\0', sizeof(szInitPABXCode));

    /*  inLoadHDTRecFromStruct(inVFHostIndex, &srLocalHDTRec);
        inLoadCPTRecFromStruct(inVFHostIndex, &srLocalCPTRec);
        vdLoadCPACParams( &srCPAC );
        inLoadTCTRec(inVFHostIndex);
        inLoadINIRec(inVFHostIndex);
        strcpy(szInitTID, szGetInitTerminalId());
        strcpy(szInitNII, szGetInitNII());
        vdGetCPACTPDU(szInitTPDU);
        memcpy(&(szInitTPDU[3]),szInitNII,3);
        strcpy(szInitPhoneNum, szGetInitPhoneNumber());
        strcpy(szInitPABXCode, szGetInitPABXCode());
        vdSetCPACNII(szInitNII);
        vdSetCPACTPDU(szInitTPDU);
        vdSetCPACTID(szInitTID);
        vdSetCPTPriAuthPhoneNumber(szInitPhoneNum, &srLocalCPTRec);
        vdSetCPTSecAuthPhoneNumber(szInitPhoneNum, &srLocalCPTRec);
        vdSetPABXCode(szInitPABXCode);
        inSaveHDTRecFromStruct(inVFHostIndex, &srLocalHDTRec);
        inSaveCPTRecFromStruct(inVFHostIndex, &srLocalCPTRec);
        inSaveCPACRec (&srCPAC);
        inSaveTCTRec(inVFHostIndex);
        inSaveINIRec(inVFHostIndex);
    */

    if (fGetDemoMode() == VS_TRUE) {
        vdDisplayMessageFromFile(BASE24_DEMO_INIT_SUCC_MSG, STATUS_MSG);
        return (VS_ERR);
    }

    inLoadHDTRec(inIndex);
    vdSetPacketType(13567); /*because we wan't Base24Init Function to be executed instead of CitiInit function*/


    inGTransactionType = INITIALISATION;

    if (obCommunication.inBegin)
        if (obCommunication.inBegin(&obCommunication, shGetCommunicationIndex(), VS_TRUE) != VS_SUCCESS)//CPAC2.1B
        {
            inGTransactionType = 0;
            vdSetPacketType(13311);
            inPFRStateStoreAll(PFR_IDLE_STATE, pobTran, 1, 1);
            return(VS_ERR);
        }
    SVC_WAIT(1000);

    if (obCommunication.inCheck)
        if (obCommunication.inCheck(&obCommunication) != VS_SUCCESS) {
            inGTransactionType = 0;
            vdSetPacketType(13311);
            inPFRStateStoreAll(PFR_IDLE_STATE, pobTran, 1, 1);
            return(VS_ERR);
        }
    SVC_WAIT(1000);
    vdGetBase24InitFName(szFName);
    if (inChkFileExist(szFName) == VS_SUCCESS)
        remove(szFName);


    fProcLastDigit = VS_FALSE;
    if ((psrHostData = psrCreateHostData()) == (HOST_8583_DATA *) NULL_CH) {
        vdFreeHostData(psrHostData);
        vdFreeVariantTables();
        vdSGErrorMessage(NO_MEM_ERR_MSG);
        inGTransactionType = 0;
        vdSetPacketType(13311);
        return (VS_ERR);
    }
    if (inInitializePacket(&obPacket) != VS_SUCCESS) {
        inGTransactionType = 0;
        vdSetPacketType(13311);
        return(VS_ERR);
    }

    if (obPacket.inInitialize(&obPacket) != VS_SUCCESS) {
        inGTransactionType = 0;
        vdSetPacketType(13311);
        return(VS_ERR);
    }

    if ((psrHostData->c8583_data = psrCreateCommData(pobTran, BASE24_SEND_SIZE, VS_FALSE)) == (COMM_8583_DATA *) NULL_CH) {
        vdSGErrorMessage(NO_MEM_ERR_MSG);
        vdFreeISO8583Data(psrHostData);
        inGTransactionType = 0;
        vdSetPacketType(13311);
        return (VS_ERR);
    }

    ((VALIDATION_STRUCT *) (psrHostData->c8583_data->v_parms))->comm_struct = psrHostData->c8583_data;

    /** Added fix for duplicate Advice **/
    psrHostData->c8583_data->validation = (int(*) (void *, int)) inCPACBaseRespValidation; //dup_adv

    vdSGCode(INITIALISATION);        /* Start of batch settlement */


    /* Disable reversal handling while doing close processing */
    psrHostData->reverse_flag = VS_FALSE;
    psrHostData->c8583_data->validation = (int(*) (void *, int)) inBaseValidationLow;
    pobTran->inTransactionCode = INITIALISATION;
    inMyTranCode = INITIALISATION;
    inStoreTranFlexiData(pobTran, AMEX_PIP_TRANS_CODE, (unsigned char *) &inMyTranCode, 2);
    if ((inPIPTransCode = shLoadPIPTransCode(inMyTranCode)) == VS_ERR) {
        vdFreeISO8583Data(psrHostData);
        inGTransactionType = 0;
        vdSetPacketType(13311);
        return (VS_ERR);
    }

    inLoadMHTRec(inGetBatchIndex());
    pobTran->srBRec.lnSTAN = lnGetSTAN();


    do {
        inIncSTAN();
        pobTran->srBRec.lnSTAN = lnGetSTAN();
        memset(szBASE24Field60, 0, sizeof(szBASE24Field60));
        vdDispMsgAt(WAIT_MSG, 1, 8, CLR_EOL);
        errno = 0;
        inRetVal = pip_trans(inPIPTransCode, psrHostData);

        memset(szField60Length, 0x00, sizeof(szField60Length));
        memcpy(szField60Length, &szBASE24Field60[0], 2);

        if ((srISO.pszField03[2] == 0x00) && (inRetVal != PIP_APPROVAL) /*&& (atoi(szField60Length))*/) /*sowmya_change*/
            break;

        if ((inRetVal == PIP_APPROVAL) && (!strncmp((char *) srISO.pszField39, "00", 2))) {
            memset(szField60Length, 0x00, sizeof(szField60Length));
            memcpy(szField60Length, &szBASE24Field60[0], 2);

            if (inSetBase24Params(&szBASE24Field60[2]) == VS_ERR) {
                vdFreeISO8583Data(psrHostData);
                obCommunication.inEnd(&obCommunication);
                inGTransactionType = 0;
                vdSetPacketType(13311);
                return (VS_ERR);
            }
        } else {
            vdFreeISO8583Data(psrHostData);
            obCommunication.inEnd(&obCommunication);
            vdSGErrorMessage(COMM_INIT_ERR_MSG);/*VENU_ADDED_MESSAGE*/

		/* Fix for Bug No 4 in Predator ICIC List  */

		inPFRStateStoreAll(PFR_IDLE_STATE, pobTran, 0, 0);
		uinCurrentState = 0;

		/* Fix for Bug No 4 in Predator ICIC List  */

            inGTransactionType = 0;
            vdSetPacketType(13311);
            return(VS_ERR);
        }

        if (srISO.pszField03[2] == 0x01)
            fProcLastDigit = VS_TRUE;
        else
            fProcLastDigit = VS_FALSE;
    } while (srISO.pszField03[2] == 0x01);
    // inRetVal = VS_ERR;

    vdFreeISO8583Data(psrHostData);
    //   if (obCommunication.inEnd)
    obCommunication.inEnd(&obCommunication);

    inGTransactionType = 0;
    vdSetPacketType(13311);

    inPFRStateStoreAll(BASE24_PFR_RECOVERY, pobTran, 1, 1);
    ACTIVITY_LOG("Init Communication Complete");

    return VS_SUCCESS;
}


/*-----------------------------------------------------------------------------
* Routine Name : int inSetHdfcParams()
* Description  : It extracts the field 60 contents of a 0810 response pkt(corresponding to a parameter download)
              and stores it in a File. The field 60 contents of the subsequent 0810 response messages (coming from the
              host as a continuation response) will be appended to this file.
              Before starting a new initialization or parameter download this file should get deleted.
* Inputs       : The data contained in Field 60.
* Outputs     : VB_ERR or VB_SUCCESS
* Notes        : Nil
*-----------------------------------------------------------------------------
*/

int inSetBase24Params(unsigned char* pchNewParameters) {
    char szFName[FNAME_SIZE + 1];
    int fHandle,
    inSize,
    inBufLength;

    inBufLength = inGetField60Length();
    vdGetBase24InitFName(szFName);
    fHandle = open(szFName, O_APPEND | O_CREAT | O_WRONLY);
    if (fHandle < 0) {
        vdSGErrorMessage(BASE24_STORAGE_FAIL_MSG);/*VENU_ADDED_MESSAGE*/
        return(VS_ERR);
    }

    inSize = write(fHandle, (char *) pchNewParameters, inBufLength);

    close(fHandle);
    if (inSize <= 0) {
        vdSGErrorMessage(BASE24_STORAGE_FAIL_MSG);/*VENU_ADDED_MESSAGE*/
        return(VS_ERR);
    }
    return(VS_SUCCESS);
}

int inGetField60Length() {
    char szLength[10 + 1];
    SVC_HEX_2_DSP(szField60Length, szLength, 2);
    szLength[4] = NULL_CH;
    return(atoi(szLength));
}


/*********************************************************************************************
* @func static void | vdGetBase24InitFName |
*
*       Loads the corresponding Init file name based on the Merchant number
*
* @parm char * | pchBFName |
*
* @rdesc VOID.
* @end
**********************************************************************************************/

void vdGetBase24InitFName(char* pchBFName) {
    sprintf(pchBFName, "%s", BASE24_INIT_FILE);
}

/*-----------------------------------------------------------------------------
* Routine Name : int inBase24UpdateHdfcTables()
* Description  : It extracts the contents of the initialization file in which the table parameters details are stored.
              It then updates all the tables with the required information.

* Inputs        : Nil
* Outputs      : VB_ERR or VB_SUCCESS
* Notes         : Nil
*-----------------------------------------------------------------------------
*/

int inBase24UpdateHdfcTables(TRANSACTION_OBJECT* pobTran) {
    char szFName[FNAME_SIZE + 1];
    int fHandle;
    int inIndex = 0,
    inRetVal = 0;
    int inCurrentTableId;
    char szBuffer[255 + 1];
    int i = 0,
    j = 0;


    //   inPFRStateStoreAll(BASE24_PFR_RECOVERY,pobTran,0,0);
    //    inSetPFRState(PFR_UPDATE_START);

    vdGetBase24InitFName(szFName);

    fHandle = open(szFName, O_RDONLY);



    if (fHandle < 0) {
        vdSGErrorMessage(BASE24_FILE_OPEN_FAIL_MSG);

	/* Fix for Bug No 4 in Predator ICIC List  */

	inPFRStateStoreAll(PFR_IDLE_STATE, pobTran, 0, 0);
	uinCurrentState = 0;

	/* Fix for Bug No 4 in Predator ICIC List  */

        return(VS_ERR);
    }

    vdResetAllTables();

    memset(szBuffer, '\0', sizeof(szBuffer));

    while ((inCurrentTableId = intableIds[inIndex]) != 5) {
        lseek(fHandle, 3L, SEEK_SET);
        vdDispMsgAt(BASE24_UPDTING_TBLS_MSG, 1, 8, CLR_EOL);

        while ((inRetVal = inGetRecord(fHandle, inCurrentTableId, szBuffer)) != VS_ERR) {
            if (inRetVal == VS_ABORT) {
                vdSGErrorMessage(BASE24_INVALID_MSG_FORMAT_MSG);
                return(VS_ERR);
            } /*This is to ensure that terminal will not end in an infinite loop of displaying Intl err 2501*/

            switch (inCurrentTableId) {
            case 1:
                vdUpdateTCT(szBuffer);
                break;
            case 2:
                vdUpdateCDT(szBuffer);
                break;
            case 3:
                j = j + 1;
                vdUpdateIITANDCDT(szBuffer, j);
                break;
            case 4:
                i = i + 1;
                vdUpdateHDT(szBuffer, i);
                break;
            default:
                break;
            }
        }
        inIndex++;
    }

    close(fHandle);

    vdFineTuneAllTables();
    inPFRStateStoreAll(PFR_IDLE_STATE, pobTran, 1, 1);

    return(VS_SUCCESS);
}


/*-----------------------------------------------------------------------------
* Routine Name : int inGetRecord(fHandle, inCurrentTableId, pstRecord)
* Description     : It extracts the tableId and length of the data in that table.
* Inputs            : fHandle,inCurrentTableId,pstRecord
* Outputs          : VB_ERR or VB_SUCCESS
* Notes             : Nil
*-----------------------------------------------------------------------------
*/

int inGetRecord(int fHandle,int inCurrentTableId,char* pstRecord) {
    char szHexTableId[1 + 1],
    szAscTableId[2 + 1];
    char szHexRecLen[2 + 1],
    szAscRecLen[4 + 1];
    char szKey[3 + 1];
    int inDataLength;

    memset(pstRecord, '\0', 256);
    memset(szKey, '\0', sizeof(szKey));



    while (read(fHandle, szKey, 3) == 3) {
        /* Get the TableId and  length */
        memset(szHexTableId, '\0', sizeof(szHexTableId));
        memset(szHexRecLen, '\0', sizeof(szHexRecLen));
        memset(szAscTableId, '\0', sizeof(szAscTableId));
        memset(szAscRecLen, '\0', sizeof(szAscRecLen));


        memcpy(szHexTableId, &(szKey[0]), 1);
        memcpy(szHexRecLen, &(szKey[1]), 2);
        SVC_HEX_2_DSP(szHexTableId, szAscTableId, 1);
        SVC_HEX_2_DSP(szHexRecLen, szAscRecLen, 2);
        szAscTableId[2] = NULL_CH;
        szAscRecLen[4] = NULL_CH;


        inDataLength = atoi(szAscRecLen);
        if (inDataLength > 250) {
            vdSGErrorMessage(BASE24_UPDTING_FAIL_MSG);
            put_env("#INIT", "1", 1);
            vdFineTuneAllTables();
            return(VS_ABORT);
            /*         vdAbort(2501);*//* changed on June 11th 2002 at HDFC Bombay */
        }
        if (inCurrentTableId == atoi(szAscTableId)) {
            read(fHandle, pstRecord, inDataLength);
            return (VS_SUCCESS);
        } else {
            /* seek to the next record */
            lseek(fHandle, (long) inDataLength, SEEK_CUR);
        }
    }
    return(VS_ERR);
}


/*-----------------------------------------------------------------------------
* Routine Name : void updateTCT(szBuffer)
* Description     : It updates the TCT table as per the input data.
* Inputs            : char *szBuffer
* Outputs          : Nil
* Notes             : Nil
*-----------------------------------------------------------------------------
*/

void vdUpdateTCT(char* pszBuffer) {
    char szheader[TERM_ADDR_SIZE + 1];
    char szHexDateTime[6 + 1],
    szAscDateTime[12 + 1],
    szDateAndTime[14 + 1];
    char szPassword[2 + 1],
    szAscPassword[4 + 1];
    char szOpt[1 + 1];
    char szInitCtrl[1 + 1],
    szAscInitCtrl[2 + 1];
    char szCurSym[1 + 1];
    char szHexCashAdv[1 + 1],
    szCashAdv[2 + 1];
    char chDLLNum;  /* szAscDLLNum[2+1];   */
    int cashAdvValue;

    inLoadTCTRec(0);
    inLoadPCTRec(0);
    inLoadMITRec((inGetMerchantNum() - 1));

    memset(szheader, 0x00, sizeof(szheader));
	 memset(szAmexHdr1, 0x00, sizeof(szAmexHdr1));
	 memset(szAmexHdr2, 0x00, sizeof(szAmexHdr2));
    memset(szCashAdv, 0x00, sizeof(szCashAdv));
    memset(szHexCashAdv, 0x00, sizeof(szHexCashAdv));
    memset(szOpt, 0x00, sizeof(szOpt));
    memset(szHexDateTime, 0x00, sizeof(szHexDateTime));
    memset(szAscDateTime, 0x00, sizeof(szAscDateTime));
    memset(szDateAndTime, 0x00, sizeof(szDateAndTime));
    memset(szPassword, 0x00, sizeof(szPassword));
    memset(szAscPassword, 0x00, sizeof(szAscPassword));
    memset(szInitCtrl, 0x00, sizeof(szInitCtrl));
    memset(szAscInitCtrl, 0x00, sizeof(szAscInitCtrl));
    memset(szCurSym, 0x00, sizeof(szCurSym));


    memset(&(chDLLNum), 0x00, sizeof(chDLLNum));
    memcpy(&(chDLLNum), &(pszBuffer[0]), 1);
    //        vdSetTCTDLLNumber(chDLLNum);

    memcpy(szInitCtrl, &(pszBuffer[1]), 1);
    SVC_HEX_2_DSP(szInitCtrl, szAscInitCtrl, 1);
    szAscInitCtrl[2] = NULL_CH;
    if (atoi(szAscInitCtrl) == 1) {
        //      if(inSetHDFCHost() == VS_SUCCESS) pClrBatch( VS_FALSE );
    }


    memcpy(szHexDateTime, &(pszBuffer[4]), 6);
    SVC_HEX_2_DSP(szHexDateTime, szAscDateTime, 6);
    szAscDateTime[12] = NULL_CH;
    memcpy(szDateAndTime, "20", 2);
    memcpy(&(szDateAndTime[2]), szAscDateTime, 12);
    szDateAndTime[14] = NULL_CH;
    SVC_CLOCK(SET_CLOCK, szDateAndTime, 14);
    //    write(hClock, szDateAndTime, 14);

    memcpy(szPassword, &(pszBuffer[11]), 2);
    SVC_HEX_2_DSP(szPassword, szAscPassword, 2);
    szAscPassword[4] = NULL_CH;
    vdSetSuperPwd(szAscPassword);
    //      vdSetSuperPwd(szAscPassword);

    //        vdSetTCTTransPwd(szAscPassword);
    //        vdSetTCTCloseSettlePwd(szAscPassword);

    memcpy(szOpt, &(pszBuffer[25]), 1);

    if ((szOpt[0] & 0x01))
        vdSetBase24AmtDualEntry(VS_TRUE);
    else
        vdSetBase24AmtDualEntry(VS_FALSE);

    // ALWAYS DISPLAYED
    //        if((szOpt[0] & 0x02))
    //        vdSetTCTFraudCtl(VB_TRUE);
    //        else
    //        vdSetTCTFraudCtl(VB_FALSE);

    if ((szOpt[0] & 0x04))
        	{
        vdSetTipProcessing(1);
	 vdSetCitiFlag(1);
        	}
    //        vdSetTCTTipProc(VB_TRUE);
    else
        	{
        vdSetTipProcessing(0);
	 vdSetCitiFlag(0);
        	}
    //        vdSetTCTTipProc(VB_FALSE);

    if (szOpt[0] & 0x20)
        vdSetBase24PrintTimeRcpt(VS_TRUE);
    else
        vdSetBase24PrintTimeRcpt(VS_FALSE);

    if (szOpt[0] & 0x40)
        vdSetDateFormat("DD/MM/YY");
    //        vdSetTCTBusiDtFormat(VB_TRUE);
    else
        vdSetDateFormat("MM/DD/YY");
    //        vdSetTCTBusiDtFormat(VB_FALSE);

    //PCT TABLE
    memcpy(szOpt, &(pszBuffer[26]), 1);
    if ((szOpt[0] & 0x02))
        vdSetEnablePrinter(VS_TRUE);
    //  vdSetTCTPrinterUsed(VB_TRUE);
    else
        vdSetEnablePrinter(VS_FALSE);
    //  vdSetTCTPrinterUsed(VB_FALSE);

    //TRT
    if ((szOpt[0] & 0x10))
        vdSetAirLineCodeReq(VS_TRUE);
    else
        vdSetAirLineCodeReq(VS_FALSE);

    if ((szOpt[0] & 0x20))
        vdSetBase24VoidOffline(VS_TRUE);
    else
        vdSetBase24VoidOffline(VS_FALSE);


    memcpy(szheader, &(pszBuffer[75]), BASE24_TERM_ADDR_SIZE);
    vdSetRctHdr1(szheader);
	 memcpy(szAmexHdr1, szheader, BASE24_TERM_ADDR_SIZE); //venu_added_base24
    //        vdSetTCTRctHdr1(szheader);
    //strcpy(szCashAdv,pszBuffer[107]);
     //memcpy(szCashAdv,&(pszBuffer[107]), 1);
//    cashAdvValue=atoi(szCashAdv);
    memcpy(szHexCashAdv, &(pszBuffer[107]), 1);
    SVC_HEX_2_DSP(szHexCashAdv, szCashAdv, 1);
    szCashAdv[2] = NULL_CH;
    cashAdvValue = atoi(szCashAdv);
    if (cashAdvValue == 1)
        vdSetBase24CashAdv(VS_TRUE);
    else
        vdSetBase24CashAdv(VS_FALSE);


    memcpy(szheader, &(pszBuffer[29]), BASE24_TERM_ADDR_SIZE);
    vdSetRctFoot4(szheader);
    //        vdSetTCTRctHdr2(szheader);

    memcpy(szheader, &(pszBuffer[52]), BASE24_TERM_ADDR_SIZE);
    vdSetRctHdr6(szheader);
   memcpy(szAmexHdr2, szheader, BASE24_TERM_ADDR_SIZE); //venu_added_base24
    //       vdSetTCTRctHdr3(szheader);

    memcpy(szCurSym, &(pszBuffer[98]), 1);
    szCurSym[1] = NULL_CH;
    //        vdSetTCTCurSymbol(szCurSym);

    memcpy(szOpt, &(pszBuffer[106]), 1);

    if ((szOpt[0] & 0x01))
        vdSetKeyboardLock(VS_TRUE);
    //        vdSetTCTKeyBdLock(VB_TRUE);
    else
        vdSetKeyboardLock(VS_FALSE); //VS_FALSE
    //        vdSetTCTKeyBdLock(VB_FALSE);

    if ((szOpt[0] & 0x02))
        vdSetBase24VoidPwdActive(VS_TRUE);
    else
        vdSetBase24VoidPwdActive(VS_FALSE);

    if ((szOpt[0] & 0x04))
        vdSetBase24RefundPwdActive(VS_TRUE);
    else
        vdSetBase24RefundPwdActive(VS_FALSE);

    if ((szOpt[0] & 0x08))
        vdSetBase24AdjustPwdActive(VS_TRUE);
    else
        vdSetBase24AdjustPwdActive(VS_FALSE);

    if ((szOpt[0] & 0x10))
        vdSetBase24ReportPwdActive(VS_TRUE);
    else
        vdSetBase24ReportPwdActive(VS_FALSE);

    inSaveTCTRec(0);
    inSavePCTRec(0);
    inSaveMITRec((inGetMerchantNum() - 1));
}


/*-----------------------------------------------------------------------------
* Routine Name : void updateCDT(pszBuffer)
* Description     : It updates the CDT table as per the input data.
* Inputs            : char *pszBuffer
* Outputs          : Nil
* Notes             : Nil
*-----------------------------------------------------------------------------
*/

void vdUpdateCDT(char* pszBuffer) {
    char szRecNum[1 + 1],
    szASCRecNum[2 + 1];
    char szPanLo[5 + 1],
    szASCPanLo[10 + 1];
    char szPanHi[5 + 1],
    szASCPanHi[10 + 1];
    char szIssuerTableId[1 + 1],
    szASCIssuerTableId[2 + 1];
    char szAcquirerTableId[1 + 1],
    szASCAcquirerTableId[2 + 1];
    char szIssuerTableDbId[1 + 1],
    szASCIssuerTableDbId[2 + 1];
    char szAcquirerTableDbId[1 + 1],
    szASCAcquirerTableDbId[2 + 1];
    char szPanLen[1 + 1],
    szASCPanLen[2 + 1];

    memset(szRecNum, '\0', sizeof(szRecNum));
    memset(szPanLo, '\0', sizeof(szPanLo));
    memset(szPanHi, '\0', sizeof(szPanHi));
    memset(szIssuerTableId, '\0', sizeof(szIssuerTableId));
    memset(szAcquirerTableId, '\0', sizeof(szAcquirerTableId));
    memset(szPanLen, '\0', sizeof(szPanLen));
    memset(szIssuerTableDbId, '\0', sizeof(szIssuerTableDbId));
    memset(szAcquirerTableDbId, '\0', sizeof(szAcquirerTableDbId));
    memset(szASCRecNum, '\0', sizeof(szASCRecNum));
    memset(szASCPanLo, '\0', sizeof(szASCPanLo));
    memset(szASCPanHi, '\0', sizeof(szASCPanHi));
    memset(szASCIssuerTableId, '\0', sizeof(szASCIssuerTableId));
    memset(szASCAcquirerTableId, '\0', sizeof(szASCAcquirerTableId));
    memset(szASCIssuerTableDbId, '\0', sizeof(szASCIssuerTableDbId));
    memset(szASCPanLen, '\0', sizeof(szASCPanLen));

    memcpy(szRecNum, &(pszBuffer[0]), 1);
    SVC_HEX_2_DSP(szRecNum, szASCRecNum, 1);
    szASCRecNum[2] = NULL_CH;

    inLoadCDTRec((atoi(szASCRecNum) - 1));

    memcpy(szPanLo, &(pszBuffer[1]), 5);
    SVC_HEX_2_DSP(szPanLo, szASCPanLo, 5);
    szASCPanLo[10] = NULL_CH;
    vdSetPANLo(szASCPanLo);


    memcpy(szPanHi, &(pszBuffer[6]), 5);
    SVC_HEX_2_DSP(szPanHi, szASCPanHi, 5);
    szASCPanHi[10] = NULL_CH;
    vdSetPANHi(szASCPanHi);

    memcpy(szIssuerTableId, &(pszBuffer[11]), 1);
    SVC_HEX_2_DSP(szIssuerTableId, szASCIssuerTableId, 1);
    szASCIssuerTableId[2] = NULL_CH;
    vdSetIssuerNum((short) atoi(szASCIssuerTableId));

    memcpy(szIssuerTableDbId, &(pszBuffer[18]), 1);
    SVC_HEX_2_DSP(szIssuerTableDbId, szASCIssuerTableDbId, 1);
    szASCIssuerTableDbId[2] = NULL_CH;
    vdSetHDFCIssuerDbIndex((short) atoi(szASCIssuerTableDbId));

    memcpy(szAcquirerTableId, &(pszBuffer[12]), 1);
    SVC_HEX_2_DSP(szAcquirerTableId, szASCAcquirerTableId, 1);
    szASCAcquirerTableId[2] = NULL_CH;
    vdSetHDFCAqIndex((short) (atoi(szASCAcquirerTableId)));

    memcpy(szAcquirerTableDbId, &(pszBuffer[19]), 1);
    SVC_HEX_2_DSP(szAcquirerTableDbId, szASCAcquirerTableDbId, 1);
    szASCAcquirerTableDbId[2] = NULL_CH;
    vdSetHDFCAqDbIndex((short) atoi(szASCAcquirerTableDbId));


    memcpy(szPanLen, &(pszBuffer[13]), 1);
    SVC_HEX_2_DSP(szPanLen, szASCPanLen, 1);
    szASCPanLen[2] = NULL_CH;

    if (atoi(szASCPanLen) == 0) {
        vdSetMinPANDigit(12);
        vdSetMaxPANDigit(19);
    }
    //      vdSetCDTPANRange("12,13,14,15,16,17,18,19");
    else {
        vdSetMinPANDigit((short) atoi(szASCPanLen));
        vdSetMaxPANDigit((short) atoi(szASCPanLen));
    }
    //      vdSetCDTPANRange(szASCPanLen);

    vdSetBase24CDTActive(VS_TRUE);
    inSaveCDTRec((atoi(szASCRecNum) - 1));
}

/*-----------------------------------------------------------------------------
* Routine Name : void vdUpdateIITANDCDT(szBuffer)
* Description     : It updates the IIT and CDT table as per the input data.
* Inputs            : char *szBuffer
* Outputs          : Nil
* Notes             : Nil
*-----------------------------------------------------------------------------
*/

void vdUpdateIITANDCDT(char* szBuffer,int j) {
    char szRecNum[1 + 1],
    szASCRecNum[2 + 1];
    char szIssuerTableId[1 + 1],
    szASCIssuerTableId[2 + 1];
    char szFloorLimit[2 + 1],
    szASCFloorLimit[4 + 1];
    char szCardLabel[10 + 1],
    szAbbCardLabel[2 + 1];
    char chDefaultActType;
    char szOpt[1 + 1],
    szOpt2[1 + 1];
    int inIndex;
    char szTipPercent[1 + 1],
    szASCTipPercent[2 + 1];
    short TipVal,
    TipFlag = j,
    TipCheckFlag = 0;
    memset(szCardLabel, '\0', sizeof(szCardLabel));
    memset(szAbbCardLabel, '\0', sizeof(szAbbCardLabel));

    memcpy(szRecNum, &(szBuffer[0]), 1);
    SVC_HEX_2_DSP(szRecNum, szASCRecNum, 1);
    szASCRecNum[2] = NULL_CH;

    inLoadIITRec((atoi(szASCRecNum) - 1));
    inLoadTCTRec(0);
    memcpy(szCardLabel, &(szBuffer[2]), 10);
    memcpy(szAbbCardLabel, szCardLabel, 2);

    vdSetIssuerLabel(szCardLabel);
    vdSetIssuerAbbrev(szAbbCardLabel);
    vdSetIssuerNumber((short) atoi(szASCRecNum));

    inSaveIITRec(( atoi(szASCRecNum) - 1));

    for (inIndex = 0; inIndex < inGetCDTTotRecs(); inIndex++) {
        inLoadCDTRec(inIndex);
        if (fGetBase24CDTActive() == VS_FALSE)
            continue;
        memset(szIssuerTableId, '\0', sizeof(szIssuerTableId));
        memset(szASCIssuerTableId, '\0', sizeof(szASCIssuerTableId));
        memset(szFloorLimit, '\0', sizeof(szFloorLimit));
        memset(szASCFloorLimit, '\0', sizeof(szASCFloorLimit));
        memset(&(chDefaultActType), '\0', sizeof(chDefaultActType));
        memset(szOpt, '\0', sizeof(szOpt));
        memset(szOpt2, '\0', sizeof(szOpt2));
        memset(szTipPercent, '\0', sizeof(szTipPercent));


        memcpy(szIssuerTableId, &(szBuffer[1]), 1);
        SVC_HEX_2_DSP(szIssuerTableId, szASCIssuerTableId, 1);
        szASCIssuerTableId[2] = NULL_CH;

        if ((((short) atoi(szASCIssuerTableId)) == inGetIssuerNum()) || (((short) atoi(szASCIssuerTableId)) == inGetHDFCIssuerDbIndex())) {
            TipCheckFlag = TipCheckFlag + 1;
            memcpy(szFloorLimit, &(szBuffer[31]), 2);
            SVC_HEX_2_DSP(szFloorLimit, szASCFloorLimit, 2);
            szASCFloorLimit[4] = NULL_CH;
            vdSetFloorLimitAmount(atol(szASCFloorLimit) * 100);

            memcpy(szTipPercent, &(szBuffer[33]), 1);
            SVC_HEX_2_DSP(szTipPercent, szASCTipPercent, 1);
            szASCTipPercent[2] = NULL_CH;
            TipVal = (short) atoi(szASCTipPercent) * 100;
            vdSetTipPercent((short) TipVal);

            memcpy(&(chDefaultActType), &(szBuffer[28]), 1);
            vdSetBase24DefaultActType(chDefaultActType);
            //                 vdSetCDTDefaultActType(chDefaultActType);

            memcpy(szOpt, &(szBuffer[24]), 1);

            if ((szOpt[0] & 0x01))
                vdSetBase24ActSelect(VS_TRUE);
            //                 vdSetCDTCustActSelect(VB_TRUE);
            else
                vdSetBase24ActSelect(VS_FALSE);
            //                 vdSetCDTCustActSelect(VB_FALSE);

            if ((szOpt[0] & 0x02))
                vdSetPinpadRequired(VS_TRUE);
            else
                vdSetPinpadRequired(VS_FALSE);

            if ((szOpt[0] & 0x04))
                vdSetManEntry(1);
            //                   vdSetCDTPANEntryMode(2);
            else
                vdSetManEntry(0);
            //               vdSetCDTPANEntryMode(1);

            if ((szOpt[0] & 0x10))
                vdSetCDTCustomBit2(VS_TRUE);  /*Ofline allowed*/
            else
                vdSetCDTCustomBit2(VS_FALSE);  /*Ofline allowed*/

            if ((szOpt[0] & 0x80))
                vdSetBase24CDTAdjustAllowed(VS_TRUE);
            else
                vdSetBase24CDTAdjustAllowed(VS_FALSE);

            memcpy(szOpt, &(szBuffer[25]), 1);

            if ((szOpt[0] & 0x01))
                vdSetChkLuhn(VS_TRUE);
            //               vdSetCDTLuhnCustom(VB_TRUE);
            else
                vdSetChkLuhn(VS_FALSE);
            //                 vdSetCDTLuhnCustom(VB_FALSE);

            if ((szOpt[0] & 0x10))
                vdSetExpDtReqd(VS_TRUE);
            //             vdSetCDTExpiryChkReq(VB_TRUE);
            else
                vdSetExpDtReqd(VS_FALSE);
            //                   vdSetCDTExpiryChkReq(VB_FALSE);

            if ((szOpt[0] & 0x20))
                vdSetBase24PhoneMailAllowed(VS_TRUE);  /*Phone Mail allowed*/
            //               vdSetCDTPhnMailAlwd(VB_TRUE);
            else
                vdSetBase24PhoneMailAllowed(VS_FALSE);  /*Phone Mail allowed*/
            //                 vdSetCDTPhnMailAlwd(VB_FALSE);

            /*  if((szOpt[0] & 0x04))
                vdSetCDTReceiptReqd(VB_TRUE);
              else
                vdSetCDTReceiptReqd(VB_FALSE);
             */
            if ((szOpt[0] & 0x40))
                vdSetCDTCustomBit3(VS_FALSE);  /*Refund allowed*/
            //              vdSetCDTRefundAlwd(VB_FALSE);
            else
                vdSetCDTCustomBit3(VS_TRUE);  /*Refund allowed*/
            //                  vdSetCDTRefundAlwd(VB_TRUE);

            if ((szOpt[0] & 0x80))
                vdSetBase24CDTPreAuthAllowed(VS_FALSE);
            else
                vdSetBase24CDTPreAuthAllowed(VS_TRUE);

            memcpy(szOpt, &(szBuffer[26]), 1);

            if ((szOpt[0] & 0x01))
                vdSetBase24CDTVoidAllowed(VS_FALSE);
            else
                vdSetBase24CDTVoidAllowed(VS_TRUE);

            //            memcpy(szCardLabel, &(szBuffer[2]), 10);
            //               vdSetCDTCardLabel(szCardLabel);

            vdSetCardLabel(szCardLabel);
            vdSetCardAbbrev(szAbbCardLabel);



            //               memcpy(szOpt, &(szBuffer[24]), 1);
            memcpy(szOpt2, &(szBuffer[27]), 1);
            if ((szOpt2[0] & 0x01))
                vdSetType(VS_TRUE);
            //                  vdSetCDTDebitTranAlwd(VB_TRUE);
            else
                vdSetType(VS_FALSE);
            //               vdSetCDTDebitTranAlwd(VB_FALSE);

            /*      if(((szOpt[0] & 0x01) && (szOpt[0] & 0x02)  && (szOpt2[0] & 0x01) ))
                  {
                      vdSetCDTHostIndex(2);
                      vdSetCDTCommIndex(2);
                       inGDebitIndex =  inIndex;
                       vdSetDebitCardIndex(inGDebitIndex);
                       vdSetDebitHostIndex(2);
                  }
                  else if(strstr(szCardLabel, "AMEX") != NULL_CH){
                    vdSetCDTHostIndex(1);
                    vdSetCDTCommIndex(1);
                    inGCreditIndex = inIndex;
                  }
                  else{
                  vdSetCDTHostIndex(0);
                  vdSetCDTCommIndex(0);
                  inGCreditIndex = inIndex;
                  }
            */

            if ((strstr(szCardLabel, "AMEX") != NULL_CH) || (strstr(szCardLabel, "JCB") != NULL_CH)) {
                vdSetHostGroupID(1);
                vdSetHostIndex(1);
                //      vdSetCDTCommIndex(1);
                //      inGCreditIndex = inIndex;
            } else {
                vdSetHostGroupID(0);
                vdSetHostIndex(0);
                //          vdSetCDTCommIndex(0);
                //      if(fGetCDTDebitTranAlwd() == VB_TRUE)
                //          {
                //              inGDebitIndex =  inIndex;
                //              vdSetDebitCardIndex(inGDebitIndex);
                //          }
            }
        }
        inSaveCDTRec(inIndex);
        if (TipFlag == 1 && TipCheckFlag == 1)
            inSaveTCTRec(0);
    }
}

/*-----------------------------------------------------------------------------
* Routine Name : void updateHDT(pszBuffer)
* Description     : It updates the HDT table,CPT table and as well as MIT table as per the input data.
* Inputs            : char *pszBuffer
* Outputs          : Nil
* Notes             : Nil
*-----------------------------------------------------------------------------
*/

void vdUpdateHDT(char* szBuffer,int i) /* venu_hdfc */ {
    char szTermId[8 + 1];/*cpacsrc.c in softpay*/
    char szMerchId[15 + 1];/*cpacsrc in softpay*/
    char szIdlePrompt[10 + 1];
    char szBatchNum[3 + 1],
    szASCBatchNum[6 + 1];/* mht.c in Softpay*/
    char szNII[2 + 1],
    szASCNII[4 + 1];/*cpacsrc.c in softpay*/
    char szPriPhone[12 + 1],
    szASCPriPhone[24 + 1];/*cpt in softpay*/
    char szSecPhone[12 + 1],
    szASCSecPhone[24 + 1];/*cpt in softpay*/
    char szPriStlPhone[12 + 1],
    szASCPriStlPhone[24 + 1];/*cpt in softpay*/
    char szSecStlPhone[12 + 1],
    szASCSecStlPhone[24 + 1];/*cpt in softpay*/
    char szModemMode[1 + 1],
    szASCModemMode[2 + 1];/*cpt in softpay*/
    char szRespTimeOut[1 + 1],
    szASCRespTimeOut[2 + 1];/*cpt in softpay*/
    char szCarrTimeOut[1 + 1],
    szASCCarrTimeOut[2 + 1];/*cpt in softpay*/
    char szHostIndex[1 + 1],
    szASCHostIndex[2 + 1];
    int inIndex = 0,
    inVFHostIndex = 0,
    inI;
    int checkFlag = i;
    //   char szCurSymbol[CUR_SYMBOL_SIZE + 1];  cst in Softpay
    char szDialAttempts[1 + 1],
    szASCDialAttempts[2 + 1];/*cpt in softpay*/
    char szTPDU[TPDU_SIZE + 1];/*cpacsrc.c*/
    CPT_REC srLocalCPTRec;
    HDT_REC srLocalHDTRec;
    /* CDT_REC srLocalCDTRec;
     MHT_REC srLocalMHTRec;*/

    /*  int    inCCITTparams[] = { 02, 03, 05, 06 , 07, 13, 15, 17, 20, 31 };  */

    memset(szHostIndex, '\0', sizeof(szHostIndex));
    memset(szASCHostIndex, '\0', sizeof(szASCHostIndex));
   memset(szAmexMerchId, '\0', sizeof(szAmexMerchId));
   memset(szAmexTermId, '\0', sizeof(szAmexTermId));

    memcpy(szHostIndex, &(szBuffer[1]), 1);
    SVC_HEX_2_DSP(szHostIndex, szASCHostIndex, 1);
    szASCHostIndex[2] = NULL_CH;

    for (inIndex = 0; inIndex < inGetCDTTotRecs(); inIndex++) {
        inLoadCDTRec(inIndex);
        if (fGetBase24CDTActive() == VS_FALSE)
            continue;

        inVFHostIndex = inGetHostGroupID();
        //  inVFHostIndex = inGetHostIndex();
        if (inVFHostIndex == 5) {
            /*this is a temp soln to check the working of TM . to be removed later*/
            vdSetHostIndex(0); /*  This is done because"  */
            vdSetHostGroupID(0);
            vdSetCardLabel("DUMMY");
            vdSetBase24CDTActive(VS_FALSE);
            inSaveCDTRec(inIndex);
            continue;
        }

        if (((inVFHostIndex == 0) && ((inGetHDFCAqIndex() == atoi(szASCHostIndex)) || (inGetHDFCAqDbIndex() == (short) atoi(szASCHostIndex)))) || ((inVFHostIndex == 1) && ((inGetHDFCAqIndex() == atoi(szASCHostIndex)) || (inGetHDFCAqDbIndex() == (short) atoi(szASCHostIndex))))) {
            inLoadHDTRecFromStruct(inVFHostIndex, &srLocalHDTRec);
            inLoadCPTRecFromStruct(inVFHostIndex, &srLocalCPTRec);
            inLoadTCTRec(0);
            inLoadMHTRec(inVFHostIndex);
            inLoadHDTRec(inVFHostIndex);
            vdLoadCPACParams(&srCPAC);/*venu_base24*/
        } else
            continue;

        //if(inVFHostIndex == 1)
        //vdSetDebitCardIndex(inGetDebitCardIndex());  /*Needs to be added inDebitCardIndex */
        //else
        //vdSetDebitCardIndex(inGCreditIndex);  /*venu_further_added */      /*inDebitCardIndex*/

        memset(szTermId, '\0', sizeof(szTermId));
        memset(szMerchId, '\0', sizeof(szMerchId));

        memset(szBatchNum, '\0', sizeof(szBatchNum));
        memset(szNII, '\0', sizeof(szNII));
        memset(szASCBatchNum, '\0', sizeof(szASCBatchNum));
        memset(szASCNII, '\0', sizeof(szASCNII));

        memset(szPriPhone, '\0', sizeof(szPriPhone));
        memset(szSecPhone, '\0', sizeof(szSecPhone));
        memset(szPriStlPhone, '\0', sizeof(szPriStlPhone));
        memset(szSecStlPhone, '\0', sizeof(szSecStlPhone));
        memset(szModemMode, '\0', sizeof(szModemMode));
        memset(szRespTimeOut, '\0', sizeof(szRespTimeOut));
        memset(szCarrTimeOut, '\0', sizeof(szCarrTimeOut));
        memset(szDialAttempts, '\0', sizeof(szDialAttempts));

        memset(szASCPriPhone, '\0', sizeof(szASCPriPhone));
        memset(szASCSecPhone, '\0', sizeof(szASCSecPhone));
        memset(szASCPriStlPhone, '\0', sizeof(szASCPriStlPhone));
        memset(szASCSecStlPhone, '\0', sizeof(szASCSecStlPhone));
        memset(szASCModemMode, '\0', sizeof(szASCModemMode));
        memset(szASCRespTimeOut, '\0', sizeof(szASCRespTimeOut));
        memset(szASCCarrTimeOut, '\0', sizeof(szASCCarrTimeOut));
        memset(szASCDialAttempts, '\0', sizeof(szASCDialAttempts));
        if (checkFlag == 1) {
            vdSetCommLinkType(inVFHostIndex);
            memcpy(szNII, &(szBuffer[83]), 2);
            SVC_HEX_2_DSP(szNII, szASCNII, 2);
            szASCNII[4] = NULL_CH;
            vdSetCPACNII(&(szASCNII[1]));

            vdGetCPACTPDU(szTPDU);
            memcpy(&(szTPDU[2]), szASCNII, (NII_SIZE + 1));
            vdSetCPACTPDU(szTPDU);

            memcpy(szTermId, &(szBuffer[85]), 8);
	   if(checkICICITIDFlag== 0)
	   	{
	   memset(szICICITermId, '\0', sizeof(szICICITermId));
	   memcpy(szICICITermId, szTermId, 8); //venu_added_base24
	   checkICICITIDFlag =1;
	   //Added by Renu
	   //Modified to fix the NII value when initialising with open batch
	   strcpy(szICICNII, &(szASCNII[1]));
	   	}
            vdSetCPACTID(szTermId);
            memcpy(szMerchId, &(szBuffer[93]), 15);
	   if(checkICICIMIDFlag == 0)
	   	{
	   	 memset(szICICIMerchId, '\0', sizeof(szICICIMerchId));
	   memcpy(szICICIMerchId, szMerchId, 15); //venu_added_base24
	   checkICICIMIDFlag =1;
	   	}
            vdSetCPACMID(szMerchId);
        }
        if (inVFHostIndex == 1) {
            vdSetCommLinkType(inVFHostIndex);
            memcpy(szNII, &(szBuffer[83]), 2);
            SVC_HEX_2_DSP(szNII, szASCNII, 2);
            szASCNII[4] = NULL_CH;
            vdSetCPACNII(&(szASCNII[1]));
	    //Added by Renu
	    //Modified to fix the NII value when initialising with open batch
	   strcpy(szAMEXNII, &(szASCNII[1]));

            vdGetCPACTPDU(szTPDU);
            memcpy(&(szTPDU[2]), szASCNII, (NII_SIZE + 1));
            vdSetCPACTPDU(szTPDU);

            memcpy(szTermId, &(szBuffer[85]), 8);
	   memcpy(szAmexTermId, szTermId, 8); //venu_added_base24
            vdSetCPACTID(szTermId);
            memcpy(szMerchId, &(szBuffer[93]), 15);
	   memcpy(szAmexMerchId, szMerchId, 15); //venu_added_base24
            vdSetCPACMID(szMerchId);
        }
        memcpy(szBatchNum, &(szBuffer[109]), 3);
        SVC_HEX_2_DSP(szBatchNum, szASCBatchNum, 3);
        szASCBatchNum[6] = NULL_CH;
        vdSetBatchNum(atol(szASCBatchNum));
	   inICICIBatchNum = atol(szASCBatchNum);

        memcpy(szPriPhone, &(szBuffer[22]), 12);
        SVC_HEX_2_DSP(szPriPhone, szASCPriPhone, 12);
        szASCPriPhone[24] = 0x00;

        for (inI = 0 ; inI < strlen(szASCPriPhone); inI++) {
            if (szASCPriPhone[inI] == 'F') {
                szASCPriPhone[inI] = 0x00;
                break;
            }
        }

        vdSetCPTPriAuthPhoneNumber(szASCPriPhone, &srLocalCPTRec);

        memcpy(szSecPhone, &(szBuffer[36]), 12);
        SVC_HEX_2_DSP(szSecPhone, szASCSecPhone, 12);
        szASCSecPhone[24] = NULL_CH;
        for (inI = 0 ; inI < strlen(szASCSecPhone); inI++) {
            if (szASCSecPhone[inI] == 'F') {
                szASCSecPhone[inI] = 0x00;
                break;
            }
        }

        vdSetCPTSecAuthPhoneNumber(szASCSecPhone, &srLocalCPTRec);
        memcpy(szPriStlPhone, &(szBuffer[50]), 12);
        SVC_HEX_2_DSP(szPriStlPhone, szASCPriStlPhone, 12);
        szASCPriStlPhone[24] = 0x00;
        for (inI = 0 ; inI < strlen(szASCPriStlPhone); inI++) {
            if (szASCPriStlPhone[inI] == 'F') {
                szASCPriStlPhone[inI] = 0x00;
                break;
            }
        }


        vdSetCPTPriSettlePhoneNumber(szASCPriStlPhone, &srLocalCPTRec);

        memcpy(szSecStlPhone, &(szBuffer[64]), 12);
        SVC_HEX_2_DSP(szSecStlPhone, szASCSecStlPhone, 12);
        szASCSecStlPhone[24] = NULL_CH;
        for (inI = 0 ; inI < strlen(szASCSecStlPhone); inI++) {
            if (szASCSecStlPhone[inI] == 'F') {
                szASCSecStlPhone[inI] = 0x00;
                break;
            }
        }



        vdSetCPTSecSettlePhoneNumber(szASCSecStlPhone, &srLocalCPTRec);

        memcpy(szModemMode, &(szBuffer[78]), 1);
        SVC_HEX_2_DSP(szModemMode, szASCModemMode, 1);
        szASCModemMode[2] = NULL_CH;
        /*          vdSetCPTModemMode(szASCModemMode);    */

        memcpy(szRespTimeOut, &(szBuffer[108]), 1);
        SVC_HEX_2_DSP(szRespTimeOut, szASCRespTimeOut, 1);
        szASCRespTimeOut[2] = NULL_CH;
        vdSetCPTRespTimeOut((short) atoi(szASCRespTimeOut), &srLocalCPTRec);

        memcpy(szCarrTimeOut, &(szBuffer[34]), 1);
        SVC_HEX_2_DSP(szCarrTimeOut, szASCCarrTimeOut, 1);
        szASCCarrTimeOut[2] = NULL_CH;
        vdSetCPTCarrierTimeOut((short) atoi(szASCCarrTimeOut), &srLocalCPTRec);


        memcpy(szDialAttempts, &(szBuffer[35]), 1);
        SVC_HEX_2_DSP(szDialAttempts, szASCDialAttempts, 1);
        szASCDialAttempts[2] = NULL_CH;
        vdSetCPTNumOfTries((short) atoi(szASCDialAttempts), &srLocalCPTRec);

        memcpy(szIdlePrompt, &(szBuffer[12]), 10);/*Needes to be changed*/
        /*vdSetTCTIdlePrompt(szIdlePrompt);*/ /*Needs to be find out where
                                              this particular field is located in Softpay*/

        /*     vdGetTCTCurSymbol(szCurSymbol);  There is a req from HDFC that the currency symbol should be Rs & not R. So we are disabling it.
                 vdSetHDTCurSymbol(szCurSymbol);  & not extracting from Base24 profile, ie TCT for updation.
        */
        /* vdSetHDTOfflineVoid(fGetTCTOfflineVoid());
        vdSetHDTReceiptReqd(fGetTCTPrinterUsed());  */

        vdSetCPTCPTActive(VS_TRUE, &srLocalCPTRec);
        vdSetHDTActive(VS_TRUE); /*venu_hdfc*/

        inSaveTCTRec(0);
        inSaveHDTRecFromStruct(inVFHostIndex, &srLocalHDTRec);
        inSaveCPTRecFromStruct(inVFHostIndex, &srLocalCPTRec);
        inSaveMHTRec(inVFHostIndex);
        inSaveCPACRec(&srCPAC);
    }
}

/*-----------------------------------------------------------------------------
* Routine Name : void vdResetAllTsbles()
* Description     : It Resets all the tables by reseting the initActive flag to 0. By having a value zero
                 all tables are deactivated. It also sets the comm & host index of CDT to an imaginary value 5.
                 The indexes then get updated to a new value which will be either 0, 1 or 2.
* Inputs            : Nil
* Outputs          : Nil
* Notes             : Nil
*-----------------------------------------------------------------------------
*/
void vdResetAllTables(void) {
    int inI = 0;
    CPT_REC srLocalCPTRec;
    //    CPAC_REC srCPAC;
    //CPT_REC *srCPTRec;

    for (inI = 0; inI < inGetCDTTotRecs(); inI++) {
        inLoadCDTRec(inI);
        vdSetBase24CDTActive(VS_FALSE);
        vdSetHostIndex(5); // 5
        vdSetHostGroupID(5);
        vdSetCardLabel("DUMMY");
        vdSetCardAbbrev(" ");
        vdSetPANLo(" ");
        vdSetPANHi(" ");
        //vdSetMinPANDigit();
        //vdSetMaxPANDigit();
        vdSetIssuerNum(0);
        inSaveCDTRec(inI);
    }

    for (inI = 0; inI < inGetIITTotRecs(); inI++) {
        inLoadIITRec(inI);
        vdSetIssuerLabel("DUMMY");
        vdSetIssuerAbbrev(" ");
        vdSetIssuerNumber(0);
        inSaveIITRec(inI);
    }

    for (inI = 0; inI < inGetHDTTotRecs(); inI++) {
        inLoadHDTRec(inI);
        vdLoadCPACParams(&srCPAC);
        vdSetCPACTID(" ");
        vdSetCPACMID(" ");
        inSaveCPACRec(&srCPAC);
    }

    for (inI = 0; inI < inGetHDTTotRecs(); inI++) {
        inLoadCPTRecFromStruct(inI, &srLocalCPTRec);
        /*srCPTRec = pvdGetCPTRec();*/
        vdSetCPTPriAuthPhoneNumber(" ", &srLocalCPTRec);
        vdSetCPTSecAuthPhoneNumber(" ", &srLocalCPTRec);
        vdSetCPTPriSettlePhoneNumber(" ", &srLocalCPTRec);
        vdSetCPTSecSettlePhoneNumber(" ", &srLocalCPTRec);
        /*vdSetCPTPriAuthPhoneNumber(" ", srCPTRec);
        vdSetCPTSecAuthPhoneNumber(" ", srCPTRec);
        vdSetCPTPriSettlePhoneNumber(" ", srCPTRec);
        vdSetCPTSecSettlePhoneNumber(" ", srCPTRec);
        inSaveCPTRec(inI);*/
        inSaveCPTRecFromStruct(inI, &srLocalCPTRec);
    }
}


/*-----------------------------------------------------------------------------
* Routine Name : void vdFineTuneAllTables()
* Description     : It checks all the CDTs which still have indexes(Host & Comm) of 5, meaning they haven't received any record
                          from the host. Once the records are identified, the indexes are mandatorily set to 2, though this index will
                          correspond to AMEX in this HDFC application. This will not affect the functioning of the application because
                          the records are marked inactive.This is done because if the CDTs are allowed to have have indexes of 5,
                          then on restarting the terminal or changing to Training mode will result in crashing of the application.
* Inputs            : Nil
* Outputs          : Nil
* Notes             : Nil
*-----------------------------------------------------------------------------
*/
void vdFineTuneAllTables() {
    short inI = 0;
    VS_BOOL fFlag = VS_FALSE;
    int inNumCDTRecords = inGetCDTTotRecs();

    for (inI = 0; inI < inNumCDTRecords; inI++) {
        inLoadCDTRec(inI);
        if (inGetHostGroupID() == 5) {
            vdSetHostGroupID(0);
            vdSetHostIndex(0);
            vdSetBase24CDTActive(VS_FALSE);  /*May 14th 2002 Sowmya to verify this later..to overcome Intl error 2501*/
            inSaveCDTRec(inI);
        }
    }
    /*    for(inI =0; inI <inGetCDTTotRecs(); inI++)
        {
        inLoadCDTRec(inI);
        if((fGetCDTInitActive() == VB_TRUE) && (fGetCDTDebitTranAlwd() == VB_TRUE) && (inGetDebitHostIndex() >= 0))
        {
            fFlag = VB_TRUE;
            vdSetDebitHostIndex(1);
            vdSetDebitCardIndex(inI);
            break;
        }
        }
        if(fFlag == VB_FALSE)
        {
        vdSetDebitHostIndex(-1);
        vdSetDebitCardIndex(-1);
        }
       */
}
int inBase24PreauthAllowed(TRANSACTION_OBJECT* pobTran) {
    short inTranType;
    inTranType = pobTran->srTRTRec.TransactionCode;
    if (inLoadCDTRec(pobTran->srBRec.inCDTIndex) != VS_SUCCESS)
        return(VS_ERR);

    if (inTranType == REFUND) {
        if (fGetCDTCustomBit3() == VS_FALSE) {
            vdSGErrorMessage(TRANS_NOT_ALLWD_ERR_MSG);
            return (VS_ERR);
        }
    }
    if (inTranType == PRE_AUTH) {
        if (fGetBase24CDTPreAuthAllowed() == VS_FALSE) {
            vdSGErrorMessage(TRANS_NOT_ALLWD_ERR_MSG);
            return (VS_ERR);
        }
    }
    return(VS_SUCCESS);
}

int inBase24CheckTranAllowed(TRANSACTION_OBJECT* pobTran) {
    short inTranType;
    inTranType = pobTran->srTRTRec.TransactionCode;
    if (inLoadCDTRec(pobTran->srBRec.inCDTIndex) != VS_SUCCESS)
        return(VS_ERR);
    switch (inTranType) {
    case VOID:
    case BATCH_REVIEW_VOID:
        if (fGetBase24CDTVoidAllowed() == VS_FALSE) {
            vdSGErrorMessage(TRANS_NOT_ALLWD_ERR_MSG);
            return (VS_ERR);
        }
        break;
    case ADJUST:
    case CPAC_PHIL_ADJUST:
        if (fGetBase24CDTAdjustAllowed() == VS_FALSE) {
            vdSGErrorMessage(TRANS_NOT_ALLWD_ERR_MSG);
            return (VS_ERR);
        }
        break;
    case PRE_AUTH:
        if (inLoadCDTRec(pobTran->srBRec.inCDTIndex) != VS_SUCCESS)
            return(VS_ERR);
        if (fGetBase24CDTPreAuthAllowed() == VS_FALSE) {
            vdSGErrorMessage(TRANS_NOT_ALLWD_ERR_MSG);
            return (VS_ERR);
        }
        break;
    case PHONE:
        if (fGetBase24PhoneMailAllowed() == VS_FALSE) {
            vdSGErrorMessage(TRANS_NOT_ALLWD_ERR_MSG);
            return (VS_ERR);
        }

        break;
    default:
        return(VS_SUCCESS);
    }

    return (VS_SUCCESS);
}


int inBase24InitAllowed(TRANSACTION_OBJECT* pobTran) {
    char szInit[1 + 1];
    memset(szInit, '\0', sizeof(szInit));
    get_env("#INIT", szInit, sizeof(szInit));
    if (atoi(szInit)) {
        vdSGErrorMessage(BASE24_PLS_INITIALIZE_MSG);
        return (VS_ERR);
    }
    return(VS_SUCCESS);
}

int inBase24ResetInitFlag(TRANSACTION_OBJECT* pobTran) {
    put_env("#INIT", "0", 1);
    vdDisplayMessageFromFile(BASE24_UPDATE_SUCC_MSG, STATUS_MSG);
    vdCITINormalBeep(100);
    return(VS_SUCCESS);
}

/*********************************************************************************************
* @func int | inEditBase24INIOperations |
*       Edit the INI configuration table
*
* @parm TRANSACTION_OBJECT * |pobTran |
*       Transaction object.
*
* @rdesc return values.
* @flag int    |  BRANCH_EXIT
* @end
**********************************************************************************************/

int inEditBase24INIOperation(TRANSACTION_OBJECT* pobTran) {
    char szTempPABX[PABX_CODE_SIZE + 1];

    memset(szTempPABX, 0x00, sizeof(szTempPABX));
    /** /pdebug(("--inEditBase24INIOperation--"));*/
    inConfRecEdit("INI");

    inLoadTCTRec(0);
    inLoadINIRec(0);
    strcpy(szTempPABX, szGetInitPABXCode());
    vdSetPABXCode(szTempPABX);
    inSaveTCTRec(0);

    return(BRANCH_EXIT);
}


/*********************************************************************************************
* @func int | inBase24DefaultSetModemObjectFunctions|
*
*       Set the Modem object function pointers
*
* @parm MODEM_OBJECT *| obModem
*
* @end
**********************************************************************************************/
int inBase24DefaultSetModemObjectFunctions(MODEM_OBJECT* obModem) {
#if 0
if(inGGOpCode() == BASE24_INIT_OPERATION)
{
#endif /* 0 */
    obModem->vdGetPriAuthPhoneNumber = vdGetINIInitPriPhoneNumber;
    obModem->vdGetSecAuthPhoneNumber = vdGetINIInitSecPhoneNumber;
    obModem->szGetPABXCode = szGetINIInitPABXCode;
#if 0
}
else
{
    obModem->vdGetPriAuthPhoneNumber    =   vdGetCPTPriAuthPhoneNumber;
    obModem->vdGetSecAuthPhoneNumber    =   vdGetCPTSecAuthPhoneNumber;
    obModem->szGetPABXCode          =   szGetPABXCode;
}
#endif /* 0 */

    obModem->vdGetPriSettlePhoneNumber = vdGetCPTPriSettlePhoneNumber;
    obModem->vdGetSecSettlePhoneNumber = vdGetCPTSecSettlePhoneNumber;
    obModem->shGetModemMode = shGetCPTModemMode;
    obModem->vdGetModemParam = vdGetCPTModemParam;
    obModem->shGetBaudRate = shGetCPTBaudRate;
    obModem->shGetDataFormat = shGetCPTDataFormat;
    obModem->shGetNumOfTries = shGetCPTNumOfTries;
    obModem->lnGetRedialDelay = lnGetCPTRedialDelay;
    obModem->lnGetMultiTransDelay = lnGetCPTMultiTransDelay;
    obModem->shGetCarrierTimeOut = shGetCPTCarrierTimeOut;
    obModem->shGetRespTimeOut = shGetCPTRespTimeOut;
    obModem->shGetInterCharTO = shGetCPTInterCharTO;
    obModem->shGetSyncSwitchDelay = shGetCPTSyncSwitchDelay;
    obModem->vdGet3101HostAddr = vdGetCPT3101HostAddr;
    obModem->fGetReconnect = fGetCPTReconnect;
    obModem->fGetModemFastConnect = fGetCPTModemFastConnect;
    obModem->fGetCommType = fGetCPTCommType;
    obModem->fGetBlindDial = fGetCPTBlindDial;

    //  obModem->fGetDialType               =   fGetCPTDialType;
    obModem->fGetDialType = fGetINIInitDialType;


    obModem->fGet3101CommType = fGetCPT3101CommType;
#if 0
if(inGGOpCode() == BASE24_INIT_OPERATION)
{
#endif /* 0 */

    obModem->vdSetPriAuthPhoneNumber = vdSetINIInitPriPhoneNumber;
    obModem->vdSetSecAuthPhoneNumber = vdSetINIInitSecPhoneNumber;
    obModem->vdSetPABXCode = vdSetINIInitPABXCode;
#if 0
}
else
{
    obModem->vdSetPriAuthPhoneNumber    =   vdSetCPTPriAuthPhoneNumber;
    obModem->vdSetSecAuthPhoneNumber    =   vdSetCPTSecAuthPhoneNumber;
    obModem->vdSetPABXCode          =   vdSetPABXCode;
}
#endif /* 0 */

    obModem->vdSetPriSettlePhoneNumber = vdSetCPTPriSettlePhoneNumber;
    obModem->vdSetSecSettlePhoneNumber = vdSetCPTSecSettlePhoneNumber;
    obModem->vdSetModemMode = vdSetCPTModemMode;
    obModem->vdSetModemParam = vdSetCPTModemParam;
    obModem->vdSetBaudRate = vdSetCPTBaudRate;
    obModem->vdSetDataFormat = vdSetCPTDataFormat;
    obModem->vdSetNumOfTries = vdSetCPTNumOfTries;
    obModem->vdSetRedialDelay = vdSetCPTRedialDelay;
    obModem->vdSetMultiTransDelay = vdSetCPTMultiTransDelay;
    obModem->vdSetCarrierTimeOut = vdSetCPTCarrierTimeOut;
    obModem->vdSetRespTimeOut = vdSetCPTRespTimeOut;
    obModem->vdSetInterCharTO = vdSetCPTInterCharTO;
    obModem->vdSetSyncSwitchDelay = vdSetCPTSyncSwitchDelay;


    obModem->vdSet3101HostAddr = vdSetCPT3101HostAddr;
    obModem->vdSetReconnect = vdSetCPTReconnect;
    obModem->vdSetModemFastConnect = vdSetCPTModemFastConnect;
    obModem->vdSetCommType = vdSetCPTCommType;
    obModem->vdSetBlindDial = vdSetCPTBlindDial;

    //  obModem->vdSetDialType              =   vdSetCPTDialType;
    obModem->vdSetDialType = vdSetINIInitDialType;

    obModem->vdSet3101CommType = vdSetCPT3101CommType;

    return(VS_SUCCESS);
}


void vdGetINIInitPriPhoneNumber(char* pszParam,CPT_REC srCPTRec) {
    if (inGTransactionType == INITIALISATION) {
        inLoadINIRec(0);
        strcpy(pszParam, szGetInitPhoneNumber());
    } else
        strlcpy(pszParam, srCPTRec.szPriAuthPhoneNumber, sizeof(srCPTRec.szPriAuthPhoneNumber));
}

void vdGetINIInitSecPhoneNumber(char* pszParam,CPT_REC srCPTRec) {
    if (inGTransactionType == INITIALISATION) {
        inLoadINIRec(0);
        strcpy(pszParam, szGetInitPhoneNumber());
    } else
        strlcpy(pszParam, srCPTRec.szSecAuthPhoneNumber, sizeof(srCPTRec.szSecAuthPhoneNumber));
}



void vdSetINIInitPriPhoneNumber(char* szPriAuthPhoneNumber,void* cptStruct) {
    CPT_REC* srCPTRec = (CPT_REC*) cptStruct;
    if (inGTransactionType == INITIALISATION) {
        inLoadINIRec(0);
        vdSetInitPhoneNumber(szPriAuthPhoneNumber);
        inSaveINIRec(0);
    } else
        strlcpy(srCPTRec->szPriAuthPhoneNumber, szPriAuthPhoneNumber, sizeof(((CPT_REC *) NULL)->szPriAuthPhoneNumber) - 1);;
}

void vdSetINIInitSecPhoneNumber(char* szSecAuthPhoneNumber,void* cptStruct) {
    CPT_REC* srCPTRec = (CPT_REC*) cptStruct;
    if (inGTransactionType == INITIALISATION) {
        inLoadINIRec(0);
        vdSetInitPhoneNumber(szSecAuthPhoneNumber);
        inSaveINIRec(0);
    } else
        strlcpy(srCPTRec->szSecAuthPhoneNumber, szSecAuthPhoneNumber, sizeof(((CPT_REC *) NULL)->szSecAuthPhoneNumber) - 1);;
}

char* szGetINIInitPABXCode(void) {
    if (inGTransactionType == INITIALISATION) {
        inLoadINIRec(0);
        return (szGetInitPABXCode());
    } else
        return (szGetPABXCode());
}


void vdSetINIInitPABXCode(const char* szPABXCode) {
    if (inGTransactionType == INITIALISATION) {
        inLoadINIRec(0);
        vdSetInitPABXCode(szPABXCode);
        inSaveINIRec(0);
    } else
        vdSetPABXCode(szPABXCode);
}

VS_BOOL fGetINIInitDialType(CPT_REC srCPTRec) {
    inLoadINIRec(0);
    return fGetInitDialType();
}

void vdSetINIInitDialType(VS_BOOL fDialType,void* cptStruct) {
    inLoadINIRec(0);
    vdSetInitDialType(fDialType);
    inSaveINIRec(0);
}

int inChkAllMerchBatchEmpty(TRANSACTION_OBJECT* pobTran) {
    int inCount;
    signed int inResult = 0;
    int inNumOfMerchants = inGetMITTotRecs();

    for (inCount = 0; inCount < inNumOfMerchants; inCount++) {
        inLoadMITRec(inCount);
        if (!fBatchEmpty(pobTran, VS_TRUE) || !fOpenTabEmpty(pobTran)) {
            inResult = obDisp.inDO_ChooseOne(pchGetMsg(HDFC_SETTLE_REQ_MSG), pchGetMsg(INIT_WARN_LINE1), pchGetMsg(YESNO_MSG5x), 2, NULL_PFI);

            if (inResult == KEY_YES)
                return(VS_SUCCESS);
            else
                return (VS_ESCAPE);

            /*vdSGErrorMessage(BATCH_NOT_EMPTY_ERR_MSG15);
                    return(VS_ERR);*/
        }
    }
    return(VS_SUCCESS);
}

int inBase24DisplayMessage(TRANSACTION_OBJECT* pobTran) {
    vdDisplayMessageFromFile(COMM_INIT_ERR_MSG, ERROR_MSG);
    return(VS_SUCCESS);
}


#if 0
init inFixBASE24Initialize()
{


    for (HDT 0 to number of HDTs)
    {
        if Batchempty (inHDTIndex) continue;
        inFixCardIndex(inHDTIndex)
    }


}

int inFixCardIndex(inHDTIndex)
{

    Load batch (inHDTIndex)
    for (record = 1 to record to MAX)
        {
            get the PAN
            if (transaction == DEBIT) new Index = new Debit Index.
            new Index = inGetNewCDTIndex (PAN)
            (if new index ==  BASE24_NO_MATCH) delete record !!! // TBD
            btch -> CDT Index = new Index
        }
}

int inGetNewCDTIndex (PAN)
{

    Scan through the CDT_CRANGE_SIZE
    return first index of CDT where PAN matches
    if no match (return BASE24_NO_MATCH)
}


#endif //FIX_BASE24

int inFixBASE24Initialize(TRANSACTION_OBJECT* pobTran) {
    int tempVar;
    int hostIndex;

    if (inHDFCChkAllMerchBatchEmpty(pobTran) == VS_SUCCESS)
        return VS_SUCCESS;
    for (hostIndex = 0; hostIndex <= 1; hostIndex++) {
        tempVar = 0;
        inLoadHDTRec(hostIndex);
        inLoadMITRec(hostIndex);
        if (inRunFunction(pobTran, OPEN_DC_BATCH) == VS_SUCCESS)
            inFixCardIndex(pobTran);
        else
            return  VS_ERR;
    }
    /*  for(hostIndex=0;hostIndex<=1;hostIndex++)
     {
        tempVar=0;
        inLoadHDTRec(hostIndex);
        inLoadMITRec(hostIndex);
        if(inRunFunction(pobTran, OPEN_TAB_BATCH) == VS_SUCCESS)
        {
         inFixCardIndex(pobTran);
        }
        else
            return VS_ERR;
     }      */
    return VS_SUCCESS;
}
int inFixCardIndex(TRANSACTION_OBJECT* pobTran) {
    long lnBatchNum;
    int inRecCnt,
    i,
    newIndex;
    int inBatchIndex;
    inBatchIndex = inGetBatchIndex();
    inLoadMHTRec(inBatchIndex);
    lnBatchNum = lnGetBatchNum();
    inRecCnt = inGetBatchRecCnt(&pobTran->dbBatch);
    for (i = 0; i < inRecCnt; i++) {
        if (inGetBatchRec(pobTran, i) != VS_SUCCESS)
            return(VS_ERR);

        newIndex = inCITILoadGetNormalCDTIndex(pobTran, pobTran->srBRec.szPAN);
        pobTran->srBRec.inCDTIndex = newIndex;
        if (inBaseAddBatchRec(pobTran, &pobTran->srBKey, &pobTran->srBRec, DB_CURRENT) != VS_SUCCESS)
            return(VS_ERR);
    }
    return VS_SUCCESS;
}



int inBaseAddBatchRec(TRANSACTION_OBJECT* pobTran,BATCH_KEY* psrBKey,BATCH_REC* psrBRec,long lnRecNum) {
    long lnDBWhat = lnRecNum;
    DB_FILE* psrDBF;

    pdebug(("--inAddBatchRec--"));

    // Load new batch record field
    pobTran->srBRec.inMerchantIndex = inGetMITIndex();

    /*
     *      Add to the Open Tab batch if it is available, otherwise operate on the Primary Batch
     */
    if (pobTran->fOTBatchOpen) {
        /** /pdebug (("Add Tab"));*/
        psrDBF = &pobTran->dbOTBatch;
    } else {
        /** /pdebug (("Add Record"));*/
        psrDBF = &pobTran->dbBatch;
    }

    if (lnRecNum == DB_CURRENT)
        lnDBWhat = ((psrDBF->kfile.curr_rec_num <= 0L) ? 0L : (psrDBF->kfile.curr_rec_num - 1));

    if (inWriteBatchData(psrDBF, psrBKey, psrBRec, lnDBWhat) != VS_SUCCESS) {

        vdSGErrorMessage(BATCH_ERR_MSG);
        return(VS_ERR);
    }

    return(VS_SUCCESS);
}

int vdPutInitWarningMessage(void) {
    char szDisplayBuffer1[DISP_STR_LEN + 1];
    char szDisplayBuffer2[DISP_STR_LEN + 1];
    char szDisplayBuffer3[DISP_STR_LEN + 1];
    char szDisplayBuffer4[DISP_STR_LEN + 1];
    int inKeyPress;
    vdWarnBeep();
    /*
            Beep

            (1,3) Transactions In Batch
            (1,5) Advised to Settle
            (1,7) Press Any Key to Cont
            Beep
            getch()
        */
    vdGetMessageFromFile(INIT_WARN_LINE1, szDisplayBuffer1);
    vdGetMessageFromFile(INIT_WARN_LINE2, szDisplayBuffer2);
    vdGetMessageFromFile(INIT_WARN_LINE3, szDisplayBuffer3);
    vdGetMessageFromFile(INIT_WARN_LINE4, szDisplayBuffer4);
    vdDisplayAt(1, 3, szDisplayBuffer1, CLR_EOL);
    vdDisplayAt(1, 4, szDisplayBuffer2, CLR_EOL);
    vdDisplayAt(1, 5, szDisplayBuffer3, CLR_EOL);
    vdDisplayAt(1, 6, szDisplayBuffer4, CLR_EOL);
    vdBeep();
    inKeyPress = get_char();
    if (inKeyPress == KEY_CANCEL) {
        vdClearNonTitleLines();
        return(VS_ERROR);
    } else {
        vdClearNonTitleLines();
        return(VS_SUCCESS);
    }
}
int inHDFCChkAllMerchBatchEmpty(TRANSACTION_OBJECT* pobTran) {
    int inCount;
    int inNumOfMerchants = inGetMITTotRecs();

    for (inCount = 0; inCount < inNumOfMerchants; inCount++) {
        inLoadMITRec(inCount);
        if (!fBatchEmpty(pobTran, VS_TRUE) || !fOpenTabEmpty(pobTran))
            return(VS_ERR);
    }
    return(VS_SUCCESS);
}
int inAXAPGetAuthCode1(TRANSACTION_OBJECT* pobTran) {
    memset(szAXAPAuthCode, '\0', sizeof(AUTH_CODE_SIZE));
    strcpy(szAXAPAuthCode, pobTran->srBRec.szAuthCode);
    return(VS_SUCCESS);
}
int inAXAPSetAuthCode1(TRANSACTION_OBJECT* pobTran) {
    strcpy(pobTran->srBRec.szAuthCode, szAXAPAuthCode);
    return(VS_SUCCESS);
}
int inUpdateMIDMultimerchant(void) {
    int inVFHostIndex;
    int inMerchantIndex;
    char szMerchId1[CPAC_MERCH_ID_SIZE + 1];
    double  dbMerchantId1;
    char szMerchId2[CPAC_MERCH_ID_SIZE + 1];
    double  dbMerchantId2;
    char szNII1[CPAC_NII_SIZE + 1],
    szNII2[CPAC_NII_SIZE+ 1];
    char szTermId1[CPAC_TERM_ID_SIZE + 1],
    szTermId2[CPAC_TERM_ID_SIZE + 1];
    long lnNumTid1,
    lnNumTid2;
    char szTPDU[CPAC_TPDU_SIZE + 1];/*cpacsrc.c*/
    char szASCNII1[4 + 1],
    szASCNII2[4 + 1];/*cpacsrc.c in softpay*/
    int l1,
    l2;
    char szHdr1[40 + 1],
    szHdr2[40 + 1],
    szHdr3[40 + 1];
    short Nom,
    TempNom;
  int i,j;
    memset(szHdr1, '\0', sizeof(szHdr1));
    memset(szHdr2, '\0', sizeof(szHdr2));
    memset(szHdr3, '\0', sizeof(szHdr3));
    memset(szMerchId1, '\0', sizeof(szMerchId1));
    memset(szMerchId2, '\0', sizeof(szMerchId2));
    memset(szNII1, '\0', sizeof(szNII1));
    memset(szNII2, '\0', sizeof(szNII2));
    memset(szTermId1, '\0', sizeof(szTermId1));
    memset(szTermId2, '\0', sizeof(szTermId2));
    memset(szASCNII1, '\0', sizeof(szASCNII1));
    memset(szASCNII2, '\0', sizeof(szASCNII2));
    inLoadHDTRec(0);
    inLoadMHTRec(0);
    inLoadINIRec(0);
    Nom = shGetNoOfMerchants();
    TempNom = 10 - Nom;
    vdLoadCPACParams(&srCPAC);
    inLoadMITRec(9);

  memcpy((char *)szMerchId1, szICICIMerchId, sizeof(szMerchId1));
  memcpy(szNII1, szICICNII, sizeof(szNII1));	//Modified to fix the NII value when initialising with open batch
  memcpy((char *)szTermId1, szICICITermId, sizeof(szTermId1));


    l1 = strlen(szTermId1);

    inLoadMHTRec(1);
    inLoadHDTRec(1);
    vdLoadCPACParams(&srCPAC);
    inLoadMITRec(9);

  memcpy((char *)szMerchId2, szAmexMerchId, sizeof(szMerchId2));
  memcpy(szNII2, szAMEXNII, sizeof(szNII2));  //Modified to fix the NII value when initialising with open batch
  memcpy((char *)szTermId2, szAmexTermId, sizeof(szTermId2));


    l2 = strlen(szTermId2);
  checkICICIMIDFlag = 0;
  checkICICITIDFlag = 0;

    for (inVFHostIndex = 0 ; inVFHostIndex <= 1; inVFHostIndex++) {
        inLoadMHTRec(inVFHostIndex);
        inLoadHDTRec(inVFHostIndex);
        for (inMerchantIndex = 0; inMerchantIndex <= Nom - 1; inMerchantIndex++) {
            inLoadMITRec(inMerchantIndex);
            vdLoadCPACParams(&srCPAC);

            if (inVFHostIndex == 0) {
                vdSetCPACMID(szMerchId1);
                vdSetCPACTID(szTermId1);
                vdSetCPACNII(szNII1);


                vdGetCPACTPDU(szTPDU);
                // pad_string(szNII1, 4, '0', LEFT);
                strcpy(szASCNII1, "0");
                strcat(szASCNII1, szNII1);
                szASCNII1[4] = NULL_CH;
                memcpy(&(szTPDU[2]), szASCNII1, 4);
                // memcpy(&(szTPDU[4]),"00000",5);

		  vdSetCPACTPDU(szTPDU);

	/* Fix for Bug No. 5 in Predator ICIC List */

                //lnNumMerchantId1 = atol(szMerchId1);
                sscanf(szMerchId1 , "%lf", &dbMerchantId1);

		dbMerchantId1= dbMerchantId1 + 1;

	memset(szMerchId1, 0x00, sizeof(szMerchId1));
                sprintf(szMerchId1, "%-15.0lf", dbMerchantId1);

	/* Fix for Bug No. 5 in Predator ICIC List */

		  lnNumTid1 = atol(szTermId1);
                lnNumTid1 = lnNumTid1 + 1;
                sprintf(szTermId1, "%ld", lnNumTid1);
		  if (l1 != strlen(szTermId1))
                    pad_string(szTermId1, l1, '0', LEFT);
                inSaveCPACRec(&srCPAC);
            }
            if (inVFHostIndex == 1) {
                vdSetCPACMID(szMerchId2);
                vdSetCPACTID(szTermId2);
                vdSetCPACNII(szNII2);
                vdGetCPACTPDU(szTPDU);
                // pad_string(szNII1, 4, '0', LEFT);
                strcpy(szASCNII2, "0");
                strcat(szASCNII2, szNII2);
                szASCNII2[4] = NULL_CH;
                memcpy(&(szTPDU[2]), szASCNII2, 4);
                // memcpy(&(szTPDU[4]),"00000",5);

                vdSetCPACTPDU(szTPDU);
              //  lnNumMerchantId2 = atol(szMerchId2);

	  /* Fix for Bug No. 5 in Predator ICIC List */

             sscanf(szMerchId2, "%lf", &dbMerchantId2);

		dbMerchantId2 = dbMerchantId2 + 1;

		memset(szMerchId2, 0x00, sizeof(szMerchId2));

             sprintf(szMerchId2, "%-15.0lf", dbMerchantId2);

	/* Fix for Bug No. 5 in Predator ICIC List */

                lnNumTid2 = atol(szTermId2);
                lnNumTid2 = lnNumTid2 + 1;
                sprintf(szTermId2, "%ld", lnNumTid2);
                if (l2 != strlen(szTermId2))
                    pad_string(szTermId2, l2, '0', LEFT);

                inSaveCPACRec(&srCPAC);
            }
        }
        for (inMerchantIndex = Nom; inMerchantIndex <= 9; inMerchantIndex++) {
            inLoadMITRec(inMerchantIndex);
            vdLoadCPACParams(&srCPAC);

            if (inVFHostIndex == 0) {
                vdSetCPACTID(" ");
                vdSetCPACMID(" ");
                // vdSetCPACNII(" ");
                inSaveCPACRec(&srCPAC);
            }
            if (inVFHostIndex == 1) {
                vdSetCPACTID(" ");
                vdSetCPACMID(" ");
                //vdSetCPACNII(" ");
                inSaveCPACRec(&srCPAC);
            }
        }
    }
    inLoadMITRec(9);
    strcpy(szHdr1, szGetRctHdr1());
    strcpy(szHdr2, szGetRctHdr6());
    strcpy(szHdr3, szGetRctFoot4());
 inLoadMITRec(0);
 vdSetRctHdr1(szAmexHdr1);
 vdSetRctHdr6(szAmexHdr2);
    vdSetRctFoot4(szHdr3);
    inSaveMITRec(0);
    inLoadMITRec(9);
    vdSetRctHdr1("");
    vdSetRctHdr6("");
    inSaveMITRec(9);
 for(i=0;i<=9;i++)
 	{
         inLoadMITRec(i);
	//  inLoadHDTRec(0);
	  for(j=0;j<=1;j++)
	  	{
	  inLoadMHTRec(j);
         vdSetBatchNum(inICICIBatchNum);
	  inSaveMHTRec(j);
 	}
 }

    return (VS_SUCCESS);
}
int inICICIRestartAfterInit(TRANSACTION_OBJECT* pobTran) {
    SVC_RESTART("");

    vdSGErrorMessage(0L);

    return(VS_SUCCESS);
}
void pad_string(char* str,int padlen,char padval,int padtype) {
    int padno;

    if ((padno = padlen - strlen(str)) > 0) {
        if (padtype == LEFT)
            memmove(str + padno, str, strlen(str) + 1);
        else
            str += strlen(str);
        memset(str, padval, padno);
        if (padtype == RIGHT)
            *(str + padno) = '\0';
    } else if (padno < 0) {
        // Truncate string if too long!!
        memmove(str, str + abs(padno), padlen + 1);
    }
}
int inICICISetTrack(TRANSACTION_OBJECT* pobTran) {
    int inIndex;
    for (inIndex = 0; inIndex < inGetCDTTotRecs(); inIndex++) {
        inLoadCDTRec(inIndex);
        if (inGetHostIndex() == 1)
            vdSetTracksRequired("3");
        else
            vdSetTracksRequired("2");
        inSaveCDTRec(inIndex);
    }
    return(VS_SUCCESS);
}

